package com.zthz.douxing.sendmessageservice.service

import com.zthz.douxing.SegmentStatus
import com.zthz.douxing.TaskInfo
import com.zthz.douxing.TripSegment
import com.zthz.douxing.event.UserWillDepartEvent
import com.zthz.douxing.msg.MessageType
import grails.transaction.Transactional

@Transactional
class ChangeBeginStatusService extends AbstractHandlerService{

    @Override
    protected String hanldTask(TaskInfo taskInfo) throws Exception {

        String resultDesc = "更改状态成功"
        String msgContent = "更改行程的状态为在OnPosition"
        UserWillDepartEvent userWillDepartEvent = formateTask2UserWillDepartEvent(taskInfo)
        try{
            msgContent = "更改行程的状态为在OnPosition"
            TripSegment tripSegment = userWillDepartEvent.tripSegment
            userWillDepartEvent.tripSegment.segmentStatus =SegmentStatus.OnPosition
            if(!tripSegment.save(flush: true)){
                resultDesc = "更改状态失败"
            }
        }catch (Exception e){
            resultDesc = "更改状态失败"
            throw e
        }finally{
            orderXingeMessageService.saveMessageToUserLog(
                    userWillDepartEvent,msgContent,resultDesc,MessageType.Before3HTripInfo)
        }

        return resultDesc
    }
}
